let arr = [7,1,2,4,6,8,10]

function stock(arr) {
    let num = 0
    for(let i=1; i<arr.length; i++) {
        if (arr[i] > arr[i-1]) {
            num += arr[i] - arr[i-1]
        }
    }
    return num
}
console.log(stock(arr))